#include <bits/stdc++.h>
using namespace std;

using i16 = short;
using i32 = int;
using i64 = long long;
using i128 = __int128_t;
using u16 = unsigned short;
using u32 = unsigned;
using u64 = unsigned long long;
using u128 = __uint128_t;
using f32 = float;
using f64 = double;
using f80 = long double;
const f80 MY_LOVE = 1.226e99L;
const i64 mod = 1226999999;
const i32 INF = 0x3f3f3f3f;
#define mpr make_pair
#define fir(p) ((p).first)
#define sec(p) ((p).second)
#define brkpr(p) fir(p),sec(p)
#define prferr(str,...) fprintf(stderr,str,##__VA_ARGS__)
// #define DLOCAL
template<class T> inline T& chmin(T& a,T b) { return a=(a<b?a:b); }
template<class T> inline T& chmax(T& a,T b) { return a=(a>b?a:b); }

/*
对于所有测试数据,保证:
• 1≤T≤20;
• 1≤n,m≤10^5, 1≤L≤10^6, 1≤V≤10^3;
• 0≤di<L, 1≤v_i≤10^3, |a_i|≤10^3;
• 0≤p_1<p_2<...<p_m≤L.
*/

#define sq(x) ((x)*(x))

const i32 N = 100005;
const i32 mL = 1000005;

i32 T,n,m,p[N],L,V;
struct Car { i32 d,v,a; } car[N];
i32 nn,mm;
pair<i32,i32> c[N];
struct PP { i32 p,id,s; } al[2*N];
bool out[N];
bool iq1[N],iq2[N];

struct Seg {
	i32 tot,rt;
	struct node {
		i32 l,r,lc,rc,c;
		inline void up(node L,node R) { c=L.c+R.c; }
	} t[mL<<2];
	
	inline void clear() {
		tot=rt=0;
		memset(t,0,sizeof(t));
	}

	inline void up(i32 p) { t[p].up(t[t[p].lc],t[t[p].rc]); }

	inline i32 nnd(i32 l,i32 r,i32 c=0) {
		++tot;
		t[tot].l = l, t[tot].r = r;
		t[tot].lc = t[tot].rc = 0;
		t[tot].c = c;
		return tot;
	}

	inline void ins(i32& p,i32 l,i32 r,i32 x) {
		if(!p) p=nnd(l,r);
		if(l==r) return ++t[p].c,void();
		i32 mid=(l+r)>>1;
		if(x<=mid) ins(t[p].lc,l,mid,x);
		else ins(t[p].rc,mid+1,r,x);
		up(p);
	}
	inline i32 qry(i32 p,i32 l,i32 r,i32 L,i32 R) {
		if(L>R) return 0;
		if(!p) return 0;
		if(L<=l&&r<=R) return t[p].c;
		i32 mid=(l+r)>>1,ret=0;
		if(L<=mid) ret+=qry(t[p].lc,l,mid,L,R);
		if(mid<R) ret+=qry(t[p].rc,mid+1,r,L,R);
		return ret;
	}
} seg;

inline void solve() {
	scanf("%d%d%d%d",&n,&m,&L,&V);
	// prferr("L(%d)\n",L);
	for(i32 i=1,d,v,a; i<=n; ++i) {
		scanf("%d%d%d",&d,&v,&a);
		car[i]=Car{d,v,a};
	}
	// sort(car+1,car+n+1,[](Car a,Car b){ return a.d<b.d; });
	for(i32 i=1; i<=m; ++i) scanf("%d",p+i);
	// prferr("p:");
	// for(i32 i=1; i<=m; ++i) prferr(" %d",p[i]);
	// prferr("\n");
	nn=0;
	memset(c,0,sizeof(c));
	for(i32 i=1; i<=n; ++i) {
		if(car[i].v<=V&&car[i].a<=0) continue;
		if(car[i].a==0) c[++nn]=mpr(car[i].d,L);
		else if(car[i].a>0) {
			if(car[i].v>V) c[++nn]=mpr(car[i].d,L);
			else {
				i32 l = 1.0*(sq(V)-sq(car[i].v))/(2*car[i].a);
				if(car[i].d+l+1<=L) c[++nn]=mpr(car[i].d+l+1,L);
			}
		} else {
			i32 l = ceil(1.0*(sq(V)-sq(car[i].v))/(2*car[i].a));
			c[++nn]=mpr(car[i].d,min(car[i].d+l-1,L));
		}
	}
	// prferr("c:");
	// for(i32 i=1; i<=nn; ++i) prferr(" {%d,%d}",brkpr(c[i]));
	// prferr("\n");
	// sort(c+1,c+nn+1);
	seg.clear();
	for(i32 i=1; i<=m; ++i) seg.ins(seg.rt,0,L,p[i]);
	memset(out,0,sizeof(out));
	i32 ans1 = 0, ans2 = 0;
	for(i32 i=1; i<=nn; ++i) {
		// prferr("i(%d) L(%d) R(%d) qry(%d)\n",i,fir(c[i]),sec(c[i]),seg.qry(seg.rt,0,L,fir(c[i]),sec(c[i])));
		if(seg.qry(seg.rt,0,L,brkpr(c[i]))) ++ans1,out[i]=1;
	}
	mm=0;
	memset(al,0,sizeof(al));
	for(i32 i=1; i<=nn; ++i) {
		if(out[i]) {
			al[++mm] = PP{fir(c[i]),i,1};
			al[++mm] = PP{sec(c[i])+1,i,0};
		}
	}
	sort(al+1,al+mm+1,[](PP a,PP b){return (a.p==b.p?a.s<b.s:a.p<b.p);});
	// prferr("al:");
	// for(i32 i=1; i<=mm; ++i) {
	// 	prferr(" {%d,%d,%d}",al[i].p,al[i].id,al[i].s);
	// }
	// prferr("\n");
	// prferr("-----\n");
	memset(iq1,0,sizeof(iq1));
	memset(iq2,0,sizeof(iq2));
	deque<i32> q1,q2;
	// q1 checked; q2 in queue
	for(i32 i=1; i<=mm; ++i) {
		if(al[i].s) {
			q2.push_back(al[i].id); iq2[al[i].id]=1;
		} else {
			if(iq1[al[i].id]) {
				while(!q1.empty()) {
					iq1[q1.front()]=0;
					q1.pop_front();
				}
			}
		}
		if(i<mm && !q2.empty() && seg.qry(seg.rt,0,L,al[i].p,al[i+1].p-1)) {
			if(q1.empty()) ++ans2;
			while(!q2.empty()) {
				q1.push_back(q2.front());
				iq1[q2.front()]=1;
				iq2[q2.front()]=0;
				q2.pop_front();
			}
		}
		// prferr("q1:");
		// for(auto x:q1) prferr(" %d",x);
		// prferr("\n");
		// prferr("q2:");
		// for(auto x:q2) prferr(" %d",x);
		// prferr("\n");
		// prferr("-----\n");
	}
	printf("%d %d\n",ans1,m-ans2);
}

signed main() {
	// #if !defined(DLOCAL) && !defined(DLOCALI)
	freopen("detect.in","r",stdin);
	// #endif
	// #if !defined(DLOCAL) && !defined(DLOCALO)
	freopen("detect.out","w",stdout);
	// #endif
	scanf("%d",&T);
	// prferr("T(%d)\n",T);
	while(T--) solve();
	// for(i32 i=1; i<=T; ++i) {
		// prferr("----- TEST CASE #%d\n",i);
		// solve();
		// if(i==2) break;
	// }
}
